package com.example.oracle.controller;

import com.example.oracle.entity.UserEntity;
import com.example.oracle.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description: 控制器
 * @author: ydf
 * @date: 2020/12/20 23:53
 * @version: v1.0
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService iUserService;

    /**
     * 查询用户列表
     * @return 返回List集合
     */
    @GetMapping("/list")
    public List<UserEntity> list(){
        List<UserEntity> list = iUserService.list();
        return list;
    }

    /**
     * 自定义Oracle SQL根据id查询用户信息
     * @param userId 用户id
     * @return 返回查询用户对象
     */
    @GetMapping("/getById/{userId}")
    public UserEntity getById(@PathVariable Integer userId){
        UserEntity userEntity = iUserService.getUserById(userId);
        return userEntity;
    }
}
